/*
PARI/GP script to prepare real constant data for OEIS
=============================================================
File: WriteRealForOEIS.txt    
Link: https://oeis.org/wiki/File:WriteRealForOEIS.txt
=============================================================
Last update: 19 Nov 2016
This file is now obsolete: content was merged with EbIo.txt
*/


Real2OEIS(file,cnst,dgts=1000) = 
/* ----------------------------------------------------------
  Writes into a text file all one needs to submit to OEIS a
  real constant x, evaluated to current "realprecision"
  digits. The default precision of x is 105 digits.
  Arguments:
  file ... String specifying the file "path+name".
  cnst ... a t_REAL constant.
  dgts ... The number of desired digits (any natural number) 

  Appends the following text into the output "file.txt":
  <Input value>
  <OFFSET> \\ +1 for 3.1, 0 for 0.31, -5 for 3.1e-6
  <DATA>   
  [<105 digits, starting with the first non-zero one>]
  <B-File>   
  <offset+0 1st non-zero digit>
  <offset+1 2nd digit>
  <offset+2 2nd digit>
  <offset+3 2nd digit>
  etc., until
  <offset+dgts dgts-th digit>,
  or less, if cnst has a lower precision.


  User instructions:
  a) If possible, evaluate the argument cnst with at least
     110 digits. If you intend to upload a b-file with a higher
     precision than 105 digits (OEIS default for DATA section),
     evaluate cnst with that precision, plus some extra digits
     (better test how many are required by evaluating it twice
     with various precisions. 
     For example, if a precision of 2000 digits is desired,
     specify something like default(realprecision,2020) before
     evaluating cnst (including any preparatory values).
     Note that PARI includes a built-in estimate of how precise
     any specific t_REAL value is. If precision(cnst)-2 returns
     fewer digits than what you requested, the function will
     override your request (PARI is not infallible in its
     precision estimates and may be too optimistic).
     Even with all such precautions, the final decision about
     how many truly significant digits the result has is your
     responsability.
  b) - Open the output file with Notepad or Wordpad.
     - First there is the plain decimal value of cnst (all
       digits). A reasonable section of that goes in the
       "EXAMPLE" section of the submission form.
     - Then there is a line with the OFFSET value. 
     - Then there is a block of max 105 digits, separated
       by comma+space, to copy and paste into "DATA" section.
     - Thereafter come two properly indexed columns which
       constitute the B-File, to the specified precision,
       or less when fewer digits are available.

  Once you have copied the DATA, OFFSET, and EXAMPLE sections,
  eliminate the file header until the "B-File:" line, and save
  what remains as the b-file. If you want to cut away some more
  trailing digits which you think might be in doubt, do so now,
  before uploading the b-file to OEIS. For example, having used
  2200 digits of realprecision, you might want to truncate the
  B-file to 2000 digits to be published.

  Example: Real2OEIS("c:\\myoeis\\b654321.txt",%33)
  Note the double backslashes in the file name string.
---------------------------------------------------------- */
{
  if (type(cnst)!="t_REAL",error("Argument must be t_REAL"));
  my (offst=0,digful=precision(cnst)-2,dig105=105,x,v);
  if (dig105>digful,dig105=digful);
  if (digful>dgts,digful=dgts);
  write(file,"Full input value:\n",cnst);
  if (cnst < 0.0, x = -cnst, x = cnst);
  while (x >= 1.0, x=x/10; offst=offst+1);
  while (x  < .10, x=10*x; offst=offst-1);
  write(file,"\nOffset = ",offst);
  v = digits(floor(10^dig105*x));
  write(file,"\nDATA:");
  for(i=1,#v-1,write1(file,v[i],", "));
  write1(file,v[#v]);
  write(file,"\n\nB-File:");
  v = digits(floor(x*10^digful));
  for(i=1,#v,write(file,offst+i-1," ",v[i]));
}


/*
=============================================================
   Contributed to OEIS Wiki by Stanislav Sykora
=============================================================
*/
